﻿namespace Anurgath.Shoutbox.Services
{
    #region Usings
    using Orchard;
    using Orchard.Environment;
    using System;
    using System.Collections.Generic;
    using Orchard.ContentManagement;
    using System.Linq;
    using System.Web;
    using Orchard.Users.Models;
    #endregion

    public class Helpers : IHelpers
    {
        private readonly Work<IOrchardServices> _OrchardServices;

        #region Constructors
        public Helpers(Work<IOrchardServices> orchardServices)
        {
            _OrchardServices = orchardServices;
        }
        #endregion

        #region Methods
        public string GetUsernameFromId(int userId)
        {
            var FoundUser = _OrchardServices.Value.ContentManager.Query<UserPart>().Where<UserPartRecord>(g => g.Id.Equals(userId)).List().FirstOrDefault();

            if (FoundUser == null)
            {
                return String.Empty;
            }

            return FoundUser.UserName;
        }
        #endregion
    }
}